Skip to content

Implement Promise.withResolvers() and Promise.try(func, arg1, arg2, /* …, */ argN)#2015

Closed
retyui wants to merge 1 commit into
facebook:static_hfrom
retyui:es2024-promise
Closed

Implement Promise.withResolvers() and Promise.try(func, arg1, arg2, /* …, */ argN)#2015
retyui wants to merge 1 commit into
facebook:static_hfrom
retyui:es2024-promise

Conversation

@retyui

@retyui retyui commented May 11, 2026

Copy link
Copy Markdown
Contributor

Summary

To be honest, contributing to open-source can be quite demotivating. I want to bring something useful to the community, but nobody seems interested in reviewing my pull requests: PR1 and PR2. The maintainers are unreachable, providing zero feedback on GitHub and ignore me in other social networks.

I’m fed up with trying to reach out to the promise maintainers for months, so I’ve decided to implement it directly in the Hermes engine.


Promise.try(fn, ...args) :

The Promise.try() static method takes a callback of any kind (returns or throws, synchronously or asynchronously) and wraps its result in a Promise.

Promise.try(() => func(arg1, arg2));
// or you can do this 
Promise.try(func, arg1, arg2);

Promise.withResolvers() :

Promise.withResolvers() is exactly equivalent to the following code:

let resolve, reject;
const promise = new Promise((res, rej) => {
  resolve = res;
  reject = rej;
});

Test Plan

you run examples from MDN

@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label May 11, 2026
@lavenzg

lavenzg commented May 11, 2026

Copy link
Copy Markdown
Contributor

We are already working on Promise, probably will land them soon. Also hermes already supports withResolvers.

@lavenzg lavenzg closed this May 11, 2026
@tmikov

tmikov commented May 11, 2026

Copy link
Copy Markdown
Contributor

One more note: Hermes has forked the polyfill, so any changes must be applied directly.

@retyui

retyui commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

Also hermes already supports withResolvers.

@lavenzg as I see there is no such methods in the latest RN ver.

Screenshot 2026-05-12 at 10 14 21
console.log(('---xdbg ' + ' '.repeat(60)).substr(0, 50), {
  'Promise.try': Promise.try,
  'Promise.withResolvers': Promise.withResolvers,
});

{"Promise.try": undefined, "Promise.withResolvers": undefined}

@retyui

retyui commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

Hermes has forked the polyfill

@tmikov if it was forked, why the Hermes still uses an original package

"promise": "8.3.0"

@tmikov

tmikov commented May 12, 2026

Copy link
Copy Markdown
Contributor

@retyui,

withResolvers

Also hermes already supports withResolvers.

@lavenzg as I see there is no such methods in the latest RN ver.

core.withResolvers = function () {

Polyfill

Hermes has forked the polyfill

@tmikov if it was forked, why the Hermes still uses an original package

It is not.

echo "ERROR: This script is deprecated." >&2
echo "The upstream 'promise' npm package (v8.3.0) is no longer maintained." >&2
echo "Make changes directly in lib/InternalJavaScript/01-Promise.js instead." >&2

@lavenzg

lavenzg commented May 12, 2026

Copy link
Copy Markdown
Contributor

Also hermes already supports withResolvers.

@lavenzg as I see there is no such methods in the latest RN ver.

Screenshot 2026-05-12 at 10 14 21 ```tsx console.log(('---xdbg ' + ' '.repeat(60)).substr(0, 50), { 'Promise.try': Promise.try, 'Promise.withResolvers': Promise.withResolvers, });

{"Promise.try": undefined, "Promise.withResolvers": undefined}

It's not in the current Hermes V1 (the version used by RN) yet. But it's in static_h and staging (260318099.0.0-staging).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants